<?php
/**
 *
 * 版权所有：恰维网络<qwadmin.qiawei.com>
 * 作    者：寒川<hanchuan@qiawei.com>
 * 日    期：2016-09-20
 * 版    本：1.0.0
 * 功能说明：后台首页控制器。
 *
 **/

namespace ZmrxiaoshuoApi\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
		//设置免费活动结束
    	$activity = D("activity")->where("status = 1")->select();    	
    	foreach($activity as $key=>$item){
    		$end_date = $item["end_time"]." 23:59:59";
    		if(strtotime($end_date) <= time()){
    			D("activity")->where("id = ".$item["id"])->save(array("status"=>0));
    		}    			
    	}
		
		//设置年费会员是否到期
		$vip_rs = D("user")->field("open_id,vip_end_date")->where("is_vip = 1")->select();
		
		foreach($vip_rs as $vip_key=>$vip_item){
			//echo strtotime($vip_item["vip_end_date"]." 23:59:59")." ".time();
			if(strtotime($vip_item["vip_end_date"]." 23:59:59") < time()){
				D("user")->where("open_id = '".$vip_item["open_id"]."'")->save(array("is_vip"=>0,"vip_begin_date"=>"0000-00-00","vip_end_date"=>"0000-00-00"));
			}
		}
    }
	
	public function testapi(){
		echo json_encode(array("1"=>"test1","2"=>test2));
	}
}